package leetcode;

import util.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0783.java
 * @Author : WangRuoyu
 * @Date 2023/11/11 22:46
 */


public class Q0783 {
    private List<Integer> list = new ArrayList<>();

    private void inorder(TreeNode node) {
        if (node == null) return;
        inorder(node.left);
        list.add(node.val);
        inorder(node.right);
    }

    public int minDiffInBST(TreeNode root) {
        inorder(root);
        int res = Integer.MAX_VALUE;
        for (int i = 1; i < list.size(); i++) {
            res = Math.min(res, list.get(i) - list.get(i - 1));
        }
        return res;
    }

    public static void main(String[] args) {
        Q0783 sl = new Q0783();
    }
}